/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

import java.awt.Point;
import javax.swing.JComponent;
import javax.swing.JLabel;

/**
 *
 * @author Александр
 */
public class Action {
    private Point mPointTo = null;
    private MovementSpeed mSpeed = null;
    private JComponent mComponent;
    private int mDelay = 0;
    private Orientation mOrientation = null;
    private RotatableLabel mLabelForRotate = null;
    private Boolean mIsTurnFaceUp = null;
    private UICard mCard = null;
    
    private JLabel mLabelForValue = null;
    private String mValueForLabel = null;
    
    private UICard mUICardForZOrder = null;
    private int mZOrder;
    
    // Действие не может быть осуществлено 
    // раньше завершения действия этого компонента 
    JComponent mPreviousComponent = null; 

    
    public Action(JComponent component, int delaySteps) {
        mComponent = component;
        mDelay = delaySteps;
    }
    
    public Action(JComponent component, int toX, int toY) {
        this(component, toX, toY, MovementSpeed.NORMAL, 0);
    }
    
    public Action(JComponent component, int toX, int toY, int delaySteps) {
        this(component, toX, toY, MovementSpeed.NORMAL, delaySteps);
    }
    
    public Action(JComponent component, int dx, int dy, MovementSpeed speed, int delaySteps) {
        mPointTo = new Point(dx, dy);
        mComponent = component;
        mSpeed = speed;
        mDelay = delaySteps;
        mOrientation = null;
    }
    
 
    public Point getDestination() {
        return mPointTo;
    }
    
    public JComponent getComponent() {
        return mComponent;
    }
    
    public RotatableLabel getRotatableComponent() {
        return mLabelForRotate;
    }
    
    public MovementSpeed getSpeed() {
        return mSpeed;
    }
    
    public float getDistance() {
        return (float) Math.sqrt(getDx()*getDx() + getDy()*getDy());
    }
    
    
    public int getDx() {
        if(mPointTo == null) {
            return 0;
        } 
        return mPointTo.x - mComponent.getLocation().x;
    }
    
    public int getDy() {
        if(mPointTo == null) {
            return 0;
        } 
        return mPointTo.y - mComponent.getLocation().y;
    }
    
    public int getDelay() {
        return mDelay;
    }
    
    
    public void setOrientation(RotatableLabel labelForRotate, Orientation orientation) {
        mLabelForRotate = labelForRotate;
        mOrientation = orientation;
    }
    
    public void setTurnFaceUp(UICard card) {
        mCard = card;
        mIsTurnFaceUp = true;
    }
    
    public void setTurnFaceDown(UICard card) {
        mCard = card;
        mIsTurnFaceUp = false;
    }
    
    public Orientation getOrientation() {
        return mOrientation;
    }
    
    public boolean isRotate() {
        if (mLabelForRotate == null) {
            return false;
        }
        return true;
    }
    
    
    public boolean isTurnFaceUp() {
        if (mIsTurnFaceUp == null || ! mIsTurnFaceUp) {
            return false;
        }
        return true;
    }
    
    public boolean isTurnFaceDown() {
        if (mIsTurnFaceUp == null || mIsTurnFaceUp) {
            return false;
        }
        return true;
    }
    
     public boolean isLabelTextChange() {
        if (mValueForLabel == null) {
            return false;
        }
        return true;
    }
     
      public boolean isZOrderChange() {
        if (mUICardForZOrder == null) {
            return false;
        }
        return true;
    }
     
    
    
    public UICard getUICard() {
        return mCard;
    }
    
    public void setLabel(JLabel label, String value) {
        mLabelForValue = label;
        mValueForLabel = value;
    }
    
    public void setZOrder(UICard card, int zIndex) {
        mUICardForZOrder = card;
        mZOrder = zIndex;
    }
    
    public void updateLabelText() {
        if(isLabelTextChange()) {
            mLabelForValue.setText(mValueForLabel);
        }
    } 
    
 //   public void setPreviousComponent(JComponent previousComponent) {
 //       mPreviousComponent = previousComponent;
  //  }
    
    public String getTexLabel() {
        return mValueForLabel;
    }
    
    public JLabel getLabelForText() {
        return mLabelForValue;
    }
    
    public int getZOrder() {
        return mZOrder;
    }
    
    public UICard getUICardForZOrderChange() {
        return mUICardForZOrder;
    }
}